From 3d0f393ced80206053e18f893a17fbb81be14c8d Mon Sep 17 00:00:00 2001 From: umherirrender Date: Tue, 4 Feb 2014 19:35:10 +0100 Subject: [PATCH] Add sequence support for upsert in DatabaseOracle In the same way as in selectInsert Bug: 53710 Change-Id: I26f891da808ecdc932e29eebda71df4c17a29617 --- includes/db/DatabaseOracle.php | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/includes/db/DatabaseOracle.php b/includes/db/DatabaseOracle.php index d304444a0a..81907ba076 100644 --- a/includes/db/DatabaseOracle.php +++ b/includes/db/DatabaseOracle.php @@ -641,8 +641,12 @@ class DatabaseOracle extends DatabaseBase { } else { $first = false; } - - $sql .= $this->fieldBindStatement( $table, $col, $val ); + if ( $this->isQuotedIdentifier( $val ) ) { + $sql .= $this->removeIdentifierQuotes( $val ); + unset( $row[$col] ); + } else { + $sql .= $this->fieldBindStatement( $table, $col, $val ); + } } $sql .= ')'; @@ -773,6 +777,30 @@ class DatabaseOracle extends DatabaseBase { return $retval; } + public function upsert( $table, array $rows, array $uniqueIndexes, array $set, + $fname = __METHOD__ + ) { + if ( !count( $rows ) ) { + return true; // nothing to do + } + + if ( !is_array( reset( $rows ) ) ) { + $rows = array( $rows ); + } + + $sequenceData = $this->getSequenceData( $table ); + if ( $sequenceData !== false ) { + // add sequence column to each list of columns, when not set + foreach ( $rows as &$row ) { + if ( !isset( $row[$sequenceData['column']] ) ) { + $row[$sequenceData['column']] = $this->addIdentifierQuotes('GET_SEQUENCE_VALUE(\'' . $sequenceData['sequence'] . '\')'); + } + } + } + + return parent::upsert( $table, $rows, $uniqueIndexes, $set, $fname ); + } + function tableName( $name, $format = 'quoted' ) { /* Replace reserved words with better ones -- 2.20.1